<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="oms" uri="http://www.sf-express.com/tags/fn"%>
<style>
.dtreediv {
	overflow-y:scroll;
	overflow-x:hidden;
	vertical-align: top; 
	display: inline-block;
	height: 250px;
	margin-top: 5px;
	width: 250px;
	border: 1px inset; 
}
</style>
<script type="text/javascript">
/* var d = new dTree('d'); */
var zNodes = new Array();
	$(function(){
		
		var setting = {
				view: {
					selectedMulti: false
				},
				check: {
					enable: true,
					chkboxType:{ "Y": "ps", "N": "s"}
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			};
		
		//d.add(100,-1,"系统管理员");//根节点的父节点必须为-1；
		<c:forEach var="permission" items="${permissionList}" varStatus="status">
				
		zNodes.push({ id:<c:out value="${permission.value.id }"></c:out>, pId:<c:out value="${permission.value.parentPermisId }"></c:out>, name:"${permission.value.name }",checked:<c:out value="${permission.value.remark }"></c:out>});
		
		</c:forEach>
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		$("#saveButton").click(function(){
			getCheckedNodesId();
			$("#form").ajaxSubmit(function(data){
				 myDialog.close();
	        	 myDialog =  art.dialog({icon: data.success,content: data.message,lock:true});
	        	$("#gridTable").jqGrid("setGridParam").trigger("reloadGrid", [{page:1}]);
			});
		});
	});
	
	

</script>
			<form  method="post" id="form" action="cms/role/auths">
				<ul class="all_list">
						<li>
							<span class="all_title">角色名称：</span>
							<span><label id="roleName" name="roleName"><c:out
										value="${role.name}" /></label> <input id="roleId" name="roleId"
								type="hidden" value="<c:out value="${role.id}"/>" /></span>
						</li>
						<li class="clearfix">
							<span class="all_title l">权限列表：</span>
							<span class="l">
								<input id="permissions" name="permissions"  type="hidden" value="" />
							<div class="dtreediv" style="height:450px;width:350px;">
								<ul id="treeDemo" class="ztree"></ul>
							</div>
							</span>
							</li>
						<li class="m-t10">
							<span class="all_title">备注：</span>
							<span><textarea id="remark" class="ui_input" name="remark" style="width:300px;"></textarea></span>
						</li>
						<li>
							<span class="all_title"></span>
							<span><input type="button" id="saveButton" class="edit_btn m-r15" name="saveButton"
								value="修改"></span>
						</li>
						</ul>
			<c:forEach var="permission" items="${myPermissionList}">
				<input name="myPermissionList" type="hidden"
					value="<c:out value='${permission.id}'></c:out>" />
			</c:forEach>
			</form>
			<script type="text/javascript">
				$(function(){
					$('input[name="myPermissionList"]').each(function(){
						 $('#'+$(this).val()).attr("checked",true);
					});  
				});
				
				function getCheckedNodesId() {
					var str="";
					$("input[type='checkbox']:checked").each(function() {
						str+= $(this).attr("id")+",";
					});
					
					var zTree = $.fn.zTree.getZTreeObj("treeDemo");
					var nodes = zTree.getCheckedNodes(true);
					for(var i=0;i<nodes.length;i++){
						str+= nodes[i].id+",";
					}
					$('#permissions').attr("value",str.slice(0,str.length-1));
				}
			</script>

